<?php
/**
 * client pooling
 * @package common_lib_client
 */
/**
 * client pooling
 * @author pandajingjing
 * @package common_lib_client
 */
class client_pooling{

	/**
	 * 客户端连接池实例
	 * @var object
	 */
	private static $_objInstance=NULL;

	/**
	 * 客户端连接池
	 * @var array
	 */
	private static $_arrClient=array();

	/**
	 * 构造函数
	 */
	private function __construct(){

	}

	/**
	 * 析构函数
	 */
	function __destruct(){

	}

	/**
	 * 构造函数
	 */
	private function __clone(){

	}

	/**
	 * 获取实例
	 * @return object
	 */
	static function getInstance(){
		if(!(self::$_objInstance instanceof self)){
			self::$_objInstance=new self();
		}
		return self::$_objInstance;
	}

	/**
	 * 获取客户端连接
	 * @param string $p_strClientType
	 * @return object
	 */
	static function getClient($p_strClientType=''){
		$p_strClientType=''==$p_strClientType?get_config('default_type','client'):$p_strClientType;
		if(!isset(self::$_arrClient[$p_strClientType])){
			self::$_arrClient[$p_strClientType]=self::_loadClient($p_strClientType);
		}
		return self::$_arrClient[$p_strClientType];
	}

	/**
	 * 加载客户端
	 * @param string $p_strClientType
	 * @return object
	 */
	private static function _loadClient($p_strClientType){
		switch($p_strClientType){
			case 'curl':
			default:
				load_lib('/client/curl');
				$objClient=new client_curl();
				break;
		}
		return $objClient;
	}
}